package com.church.action;

import com.church.db.User;
import com.church.services.UserServices;
import com.opensymphony.xwork2.ActionSupport;

public class UpdateUser extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private UserServices userServices;
	private User user;

	public UserServices getUserServices() {
		return userServices;
	}

	public void setUserServices(UserServices userServices) {
		this.userServices = userServices;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String execute() {
		User dbUser = userServices.findUserById(user.getUserid());
		if (dbUser != null) {
			if (user.getAddress() != null) {
				dbUser.setAddress(user.getAddress());
			}
			if (user.getArtisticSkills() != null) {
				dbUser.setArtisticSkills(user.getArtisticSkills());
			}
			if (user.getBirthday() != null) {
				dbUser.setBirthday(user.getBirthday());
			}
			if (user.getEmail() != null) {
				dbUser.setEmail(user.getEmail());
			}
			if (user.getGraduated() != null) {
				dbUser.setGraduated(user.getGraduated());
			}
			if (user.getGroup() != null) {
				dbUser.setGroup(user.getGroup());
			}
			if (user.getMobile() != null) {
				dbUser.setMobile(user.getMobile());
			}
			if (user.getSex() != null) {
				dbUser.setSex(user.getSex());
			}
			if (user.getTelephone() != null) {
				dbUser.setTelephone(user.getTelephone());
			}
			if (user.getWorkingOrgans() != null) {
				dbUser.setWorkingOrgans(user.getWorkingOrgans());
			}
			if (user.getWorkPosition() != null) {
				dbUser.setWorkPosition(user.getWorkPosition());
			}
			userServices.update(dbUser);
		}
		return "success";
	}

}
